package com.fanrui.code.family;

import java.util.Collection;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.fanrui.proto.cmd.FamilyTrendsType;

public class FamilyTrends {
	private long playerId;
	private FamilyTrendsType trendsType;
	private long time;
	private String expandStr;
	public FamilyTrends() {
	}
	public FamilyTrends(JsonElement jsonElement) {
		if(jsonElement != null ){
			JsonObject jsonObject = jsonElement.getAsJsonObject();
			playerId = jsonObject.get("playerId").getAsLong();
			time = jsonObject.get("time").getAsLong();
			trendsType = FamilyTrendsType.forNumber(jsonObject.get("trendsType").getAsInt());
			expandStr = jsonObject.get("expandStr").getAsString();
		}
	}
	public String toJson(){
		JsonObject jsonObject = new JsonObject();
		jsonObject.addProperty("playerId", playerId);
		jsonObject.addProperty("time", time);
		jsonObject.addProperty("trendsType", trendsType.getNumber());
		jsonObject.addProperty("expandStr", expandStr);
		return jsonObject.toString();
	}
	public JsonObject toJsonObject(){
		JsonObject jsonObject = new JsonObject();
		jsonObject.addProperty("playerId", playerId);
		jsonObject.addProperty("time", time);
		jsonObject.addProperty("trendsType", trendsType.getNumber());
		jsonObject.addProperty("expandStr", expandStr);
		return jsonObject;
	}
	public static String listToJson(Collection<FamilyTrends> lists){
		JsonArray jsonArray = new JsonArray();
		for(FamilyTrends trend : lists){
			jsonArray.add(trend.toJsonObject());
		}
		
		return jsonArray.toString();
	}
	public long getPlayerId() {
		return playerId;
	}
	public void setPlayerId(long playerId) {
		this.playerId = playerId;
	}
	public FamilyTrendsType getType() {
		return trendsType;
	}
	public void setType(FamilyTrendsType type) {
		this.trendsType = type;
	}
	public long getTime() {
		return time;
	}
	public void setTime(long time) {
		this.time = time;
	}
	public String getExpandStr() {
		return expandStr;
	}
	public void setExpandStr(String expandStr) {
		this.expandStr = expandStr;
	}
	
	
}
